//
//  ProgramTableViewCell.m
//  CoolFM
//
//  Created by 曹曹 on 16/9/1.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "ProgramTableViewCell.h"
#import "Record_Plays.h"
#import "Record.h"
#import "UIImageView+WebCache.h"
#import "DJDetailBannerViewController.h"
#import "FocusProData.h"
#import "CFMacro.h"

@interface ProgramTableViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *recordImage;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *detailLabel;
@property (weak, nonatomic) IBOutlet UILabel *listenLabel;
@property (weak, nonatomic) IBOutlet UILabel *updateLabel;
@property (weak, nonatomic) IBOutlet UILabel *djLabel;
@property (weak, nonatomic) IBOutlet UIImageView *djImage;
@property (nonatomic, strong) UIViewController *vc;

@end

@implementation ProgramTableViewCell

- (void)setRecord_plays:(Record_Plays *)record_plays {
    _record_plays = record_plays;
    if (IS_IPHONE_5) {
//        _listenLabel.font = [UIFont systemFontOfSize:7];
        _updateLabel.font = [UIFont systemFontOfSize:10];
    }
    [_recordImage sd_setImageWithURL:[NSURL URLWithString:record_plays.record_play_image_url]
                    placeholderImage:[UIImage imageNamed:@"img_dj_head"]];
    _titleLabel.text = record_plays.record_play_name;
    _detailLabel.text = record_plays.record_play_description;
    _listenLabel.text = [NSString stringWithFormat:@"%ld", record_plays.record_play_listen_amount];
    if (record_plays.record_play_listen_amount > 999) {
        NSInteger single = record_plays.record_play_listen_amount / 10000;
        NSInteger deciml = record_plays.record_play_listen_amount % 10000 / 1000;
        NSString *num = [NSString stringWithFormat:@"%ld.%ld", single, deciml];
        _listenLabel.text = [NSString stringWithFormat:@"人气: %@万", num];
    }
    NSDateFormatter *format = [[NSDateFormatter alloc] init];
    format.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    NSString *createString = record_plays.record[0].record_created_at;
    NSDate *createDate = [format dateFromString:createString];
    NSTimeInterval time = [[NSDate date] timeIntervalSinceDate:createDate];
    NSInteger interval = time / 60;
    _updateLabel.text = [NSString stringWithFormat:@"%ld分钟前", interval];
    if (interval > 59) {
        _updateLabel.text = [NSString stringWithFormat:@"%ld小时前", interval / 60];
    }
    _djLabel.text = record_plays.record_play_dj;
    if ([_djLabel.text isEqualToString:@""]) {
        _djImage.alpha = 0;
    } else {
        _djImage.alpha = 1;
    }
}
#pragma mark - 点击跳转页面
- (IBAction)moreButtonClicked:(id)sender {
    DJDetailBannerViewController *djBanner = [[DJDetailBannerViewController alloc] init];
    djBanner.playKey = _record_plays.record_play_key;
    [self.vc.navigationController pushViewController:djBanner animated:YES];
}
- (UIViewController *)vc {
    id responder = self.nextResponder;
    while (![responder isKindOfClass:[UIViewController class]] && responder != nil) {
        responder = [responder nextResponder];
    }
    return (UIViewController *)responder;
}
- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
